# -*- coding: utf-8 -*-#

# -------------------------------------------------------------------------------
# Name:         init_51job_page_list_link
# Description:  初始化列表页所有url
# Author:       zhuchunxu
# Date:         2020/11/3
# -------------------------------------------------------------------------------

import redis

from spider_source.utils.redis_utils import RedisUtils


def init_page_list_link():
    # 构造省数字
    provinceids = list(range(10, 33))
    for digit in range(10):
        provinceids.append('0' + str(digit))

    prefix = 'https://search.51job.com/list/'
    middle = '0000,000000,0000,00,9,99,%2B,2,'
    suffix = '.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare='

    utils = RedisUtils()
    # 构造连接
    for province in provinceids:
        for pageno in range(1, 2001):
            url = prefix + str(province) + middle + str(pageno) + suffix
            print("插入：", url)
            utils.conn.lpush("51job:page_list_link", url)


if __name__ == "__main__":
    print("开始初始化。。。")
    init_page_list_link()
    print("执行完毕")
